/*
Disclaimer of Warranty: THE PACKAGE IS PROVIDED
BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF
THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


(c) Copyright 2013 Edward Principe
All Rights Reserved

*/
#ifndef TOKLINE_H
#define TOKLINE_H

#include <Windows.h>
#include <tchar.h>
#include <fstream>
#include <list>
#include "toknode.h"
#include "smtptr.h"

/////////////////////////////////////////////////////////////////
// TokLine: A line of tokens
////////////////////////////////////////////////////////////////
class TokLine
{
public: // Construction
    TokLine()
    {
        Init();
    }

    TokLine(const TokLine& rhs)
    {

        Init();
        Copy(rhs);
    }

public: // Methods
    void Set(const TokLine& tokens);
    void Set(const TokNode& tokens);
    void EndSet();

public: // Methods
	void Reset()
	{
		_tokens.erase(_tokens.begin(), _tokens.end());
	}

public: // Methods
    void Append(const TokLine& rhs); // Appends the class
    void Append(const TokNode& rhs);

public: // Methods
    void Read(fstream& in); // Reads a line of tokens
    void Write(fstream& out); // Writes a line of token

public: // Methods
    void SetLine(unsigned long line) {_line = line;}
    unsigned long GetLine() {return _line;}

    list<TokNode>::iterator GetBegin() {return _tokens.begin();}
    list<TokNode>::iterator GetEnd() {return _tokens.end();}

#ifdef _DEBUG
public: // Debug methods
	void Dump();
#endif

public: // Operators
    TokLine& operator = (const TokLine& rhs)
    {
        Copy(rhs);
        return *this;
    }

    TokLine& operator = (const TokNode& rhs)
    {
        _tokens.erase(_tokens.begin(), _tokens.end());
        _tokens.push_back(rhs);
        return *this;
    }

    TokLine& operator += (const TokLine& rhs)
    {
        Append(rhs);
        return *this;
    }

    TokLine& operator + (const TokLine& rhs)
    {
        Append(rhs);
        return *this;
    }

    TokLine& operator += (const TokNode& rhs)
    {
        Append(rhs);
        return *this;
    }

    TokLine& operator + (const TokNode& rhs)
    {
        Append(rhs);
        return *this;
    }

private: // Methods
    void Init()
    {
        _line = 0;
    }

    void Copy(const TokLine& rhs)
    {
        if(this == &rhs)
            return;

        _tokens.erase(_tokens.begin(), _tokens.end());

        _line = rhs._line;
        _tokens = rhs._tokens;
    }
private: // Attributes
    unsigned long _line; // Line #
    list<TokNode> _tokens; // A list of tokens
};

#endif // TOKLINE_H
